import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
} from "vue-router";
import { defineAsyncComponent } from 'vue'
import { useStore } from "@/store/index";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/Home",
  },
  {
    path: "/Home",
    name: "Home",
    component: () => import("@/view/Home/Home.vue"),
    alias: "/Home",
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/showroom",
    name: "showroom",
    component: () => import("@/view/Solutions/Solutions.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/video",
    name: "video",
    component: () => import("@/view/video/video.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/companyData",
    name: "companyData",
    component: () => import("@/view/companyData/companyData.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/demand",
    name: "demand",
    component: () => import("@/view/About/About.vue"),
    alias: "/demand",
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/details",
    name: "details",
    component: () => import("@/view/details/details.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/News",
    name: "News",
    component: () => import("@/view/News/News.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/NewsDetail",
    name: "NewsDetail",
    component: () => import("@/view/NewsDetail/NewsDetail.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/Ecology",
    name: "Ecology",
    component: () => import("@/view/Ecology/Ecology.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/EcologyDetail",
    name: "EcologyDetail",
    component: () => import("@/view/EcologyDetail/EcologyDetail.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/about",
    name: "About",
    component: () => import("@/view/JointDesign/JointDesign.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/searchData",
    name: "searchData",
    component: () => import("@/view/searchData/searchData.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/Sitemap",
    name: "Sitemap",
    component: () => import("@/view/Sitemap/Sitemap.vue"),
    meta: {
      keepAlive: true,
    },
  },
  {
    path: "/industryList",
    name: "industryList",
    component: () => import("@/view/industryList/industryList.vue"),
    meta: {
      keepAlive: true,
    },
  },
];

const router = createRouter({
  history: createWebHistory(),
  // history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    return {
      el: "#app",
      top: 0,
      behavior: "smooth",
    };
  },
});


router.beforeEach((to,from,next)=>{
    const store = useStore()
    store.updateCurrentRoute(to.name)
    next()
})

 
// function getRoutesList(routes:any, pre :any) {
//   return routes.reduce((array :any, route:any) => {
//     const path = `${pre}${route.path}`;
 
//     if (route.path !== '*') {
//       array.push(path);
//     }
 
//     if (route.children) {
//       array.push(...getRoutesList(route.children, `${path}/`));
//     }
 
//     return array;
//   }, []);
// }
 
 
// // getRoutesList(router.options.routes, 'https://zigamiklic.com');
// function getRoutesXML() {
//   const list = getRoutesList(router.options.routes, 'https://www.gjdbyy.com/')
//     .map((route:any) => `<url><loc>${route}</loc></url>`)
//     .join('\r\n');
//   return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
//     ${list}
//   </urlset>`;
// }
 
// console.log(getRoutesXML())

export default router;
